package design_pattern

import "fmt"

type IHandler interface {
	SetNext(handler IHandler)
	Handle(score int)
}

type ConcreteHandler1 struct {
	Next IHandler
}

func (c *ConcreteHandler1) Handle(score int) {
	if score < 0 {
		fmt.Println("ConcreteHandler1 处理")
		return
	}

	if c.Next != nil {
		c.Next.Handle(score)
	}

	return
}
func (c *ConcreteHandler1) SetNext(handler IHandler) {
	c.Next = handler
}

type ConcreteHandler2 struct {
	Next IHandler
}

func (c *ConcreteHandler2) Handle(score int) {
	if score > 0 {
		fmt.Println("ConcreteHandler2 处理")
		return
	}

	if c.Next != nil {
		c.Next.Handle(score)
	}

	return
}
func (c *ConcreteHandler2) SetNext(handler IHandler) {
	c.Next = handler
}

type ConcreteHandler3 struct {
	Next IHandler
}

func (c *ConcreteHandler3) Handle(score int) {
	if score == 0 {
		fmt.Println("ConcreteHandler3 处理")
		return
	}

	if c.Next != nil {
		c.Next.Handle(score)
	}

	return
}
func (c *ConcreteHandler3) SetNext(handler IHandler) {
	c.Next = handler
}

func main1() {
	handler1 := &ConcreteHandler1{}
	handler2 := &ConcreteHandler2{}
	handler3 := &ConcreteHandler3{}

	handler1.SetNext(handler2)
	handler2.SetNext(handler3)

	handler1.Handle(10)
}
